#include "colorview.h"
#include <iostream>

using namespace std;


ColorView::ColorView()
{
    widthViewer = 40;
    foregroundColor = QColor(0, 0, 0, 0);
    backgroundColor = QColor(255, 255, 255, 0);

    setMinimumSize((int) (widthViewer * 1.5 + 5), (int) (widthViewer * 1.5 + 5));

}


// we paint the graphical element
void ColorView::paintEvent (QPaintEvent * event){

   QPainter* painter = new QPainter(this);


   painter->fillRect(QRect((int) (widthViewer / 2), (int) (widthViewer / 2),
                           (int) (widthViewer), (int) (widthViewer)),
                     backgroundColor);

   painter->drawRect((int) (widthViewer / 2), (int) (widthViewer / 2),
                     (int) (widthViewer), (int) (widthViewer));

   painter->fillRect(QRect(0, 0, widthViewer, widthViewer), foregroundColor);

   painter->drawRect(0, 0, widthViewer, widthViewer);
    cout << "paint color view"<< endl;
   delete painter;

}

void ColorView::setForegroundColor(QColor colorFg){
    cout << "set forgroundColor"<< endl;
    foregroundColor = colorFg;
    repaint();

}

void ColorView::setBackgroundColor(QColor colorBg){
    cout << "set background color"<< endl;
    backgroundColor = colorBg;
    repaint();

}
